import json
from prettytable import PrettyTable
import os

domain_ID = 0
few_shot_cnt = 100

table = PrettyTable(["domain", "accuracy", "precision",
                     "recall", "f1" ])

log_dir = "./"

for item in os.walk(log_dir):
    if "metric.log" in item[2]:
        with open(os.path.join(item[0], "metric.log"), "r") as fr:
            lines = [line for line in fr]
        dic = json.loads(lines[-1].split("\t", 1)[1])['metric']
        key = list(dic.keys())[0]
        domain = key.split("_", 1)[1]
        table.add_row([domain, dic[key]['valid_acc'], dic[key]['valid_prec'],
                        dic[key]['valid_recall'], dic[key]['valid_f1']])
print(table)